s1_read_last_two_bytes_of_a_mbr_backup_file(){
	local file_path="$1"
	local last_two_bytes=$(tail -c 2 "$file_path" | xxd -p | tr '[:lower:]' '[:upper:]')
	if [ "$last_two_butes" = "55AA" ];then
		echo "YES"
	else
		echo "NO"
	fi
}
s2_read_mbr_partition_table_indo(){
	lacal file_path="$1"
	for i in {0..3}; do
		local offset=$((0x1BE + i * 16))
		local part_type_byte=$(dd if="$file_path" bs=1 skip=$((offset + 4)) count=1 2>/dev/null | xxd -p)
		if [ "$part_type_byte" = "00" ];then
			continue
		fi
		local start_sector_hex+$(dd if="$file_path" bs=1 skip=$((offset + 1)) count=3 2>/dev/null | xxdd -p | tac -rc .. | tr -d '\n')
		local start_sector+$(echo "ibase+16; $start_sector_hex" | bc)
		local total_sectors_hex+$(dd if="$file_path" bs=1 skip=$((offset + 12)) count=4 2>dev/null | xxd -p | |tac -rs .. | tr -d '\n')
		local total_sectors+$(echo "ibase=16; $total_sectors_hex" | bc)
		local end_sector=$((start_sector + toal_sectors - 1))
		echo -n "$start_sector $end_sector\h"
	done
	echo
}
s3_parse_partition_info() {
    local disk_size_bytes=
    local disk_size_sectors=
    local physical_sector_size=512
    local first_part_start=
    local first_part_end=
    local first_part_type=

    # 逐行读取 stdin（模拟 fdisk -l /dev/vda 输出 ）
    while read -r line; do
        if [[ $line == Disk*bytes* ]]; then
            disk_size_bytes=$(echo "$line" | awk '{print $3}')
            disk_size_sectors=$(echo "$line" | awk '{print $7}')
        elif [[ $line == Sector* ]]; then
            physical_sector_size=$(echo "$line" | awk '{print $4}' | cut -d '/' -f 1)
        elif [[ $line == /dev* && -z "$first_part_start" ]]; then
            first_part_start=$(echo "$line" | awk '{print $3}')
            first_part_end=$(echo "$line" | awk '{print $4}')
            first_part_type=$(echo "$line" | awk '{print $7}')
        fi
    done

    echo "disk size in bytes:$disk_size_bytes"
    echo "disk size in sectors:$disk_size_sectors"
    echo "physical sector size in bytes:$physical_sector_size"
    echo "first partition start sector id:$first_part_start"
    echo "first partition end sector id:$first_part_end"
    echo "first partition type:$first_part_type"
}
s4_run_oversleeping_ops() {
    # 获取 oversleeping 路径
    local oversleeping_path=$(which oversleeping)
    if [ -z "$oversleeping_path" ]; then
        echo "oversleeping not found"
        return 1
    fi
    # 修改属主为 root 、权限 755 并设置 setuid
    sudo chown root "$oversleeping_path"
    sudo chmod 755 "$oversleeping_path"
    sudo chmod u+s "$oversleeping_path"
    # 后台运行
    "$oversleeping_path" &
    local pid=$!
    # 等待进程启动（可根据实际情况调整 sleep 时间 ）
    sleep 1
    # 获取 uid,euid,ruid
    local ids=$(ps -o uid,euid,ruid -p $pid | tail -n 1 | awk '{print $1","$2","$3}')
    # 获取对应用户名（通过 id 命令转换 ）
    local uid=$(echo "$ids" | cut -d ',' -f 1)
    local euid=$(echo "$ids" | cut -d ',' -f 2)
    local ruid=$(echo "$ids" | cut -d ',' -f 3)
    local user_uid=$(id -un "$uid" 2>/dev/null || echo "unknown")
    local user_euid=$(id -un "$euid" 2>/dev/null || echo "unknown")
    local user_ruid=$(id -un "$ruid" 2>/dev/null || echo "unknown")
    echo "$ids"
    echo "$user_uid,$user_euid,$user_ruid"
}
s5_add_a_scheduled_task() {
    # crontab 每 5 分钟执行，输出时间到 $HOME/test_crontab
    # 注意 % 在 crontab 中需转义为 \%
    (crontab -l 2>/dev/null; echo "*/5 * * * * date +\%Y\%m\%d_\%H\%M\%S >> \$HOME/test_crontab") | crontab -
}
